home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ultra250.zip / UW_TUT4.C < prev    next >
Text File  |  1992-11-02  |  5KB  |  95 lines

  1. /****************************************************************************/
  2. /* UW_TUT4.C                                                                */
  3. /*                                                                          */
  4. /* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL    */
  5. /*                                                                          */
  6. /* Now we add a real-time clock that updates in the background!  This       */
  7. /* demonstrates the use of the UltraWin timer interrupt facility and        */
  8. /* the "background" idle function. We'll use the background function        */
  9. /* later to print data...                                                   */
  10. /*                                                         Dr. Boyd Gafford */
  11. /*                                                         Kevin Huck       */
  12. /*                                                         EnQue Software   */
  13. /*                                                         08/31/92         */
  14. /****************************************************************************/
  15. #include <time.h>
  16. #include <ctype.h>
  17. #include "uw.h"                           /* include the necessary headers  */
  18.  
  19. /*----------------------- global window variables --------------------------*/
  20. WINDOW   Desk_window, Window1;
  21.  
  22. /*-------------------------------- prototypes ------------------------------*/
  23. int disp_time( void );
  24.  
  25. /*********/
  26. /* ~main */
  27. /*       ********************************************************************/
  28. /*  Demonstrate background function and timer interrupt facility...         */
  29. /****************************************************************************/
  30. int main()
  31. {
  32.   WINDOW *wnp;
  33.   
  34.   wnp = &Window1;                         /* set local window pointer       */
  35.   init_video(80, 25);                     /* init video for 80 x 25 screen  */
  36.   init_clock(0x3333);                     /* init clock irq at 91 tics/sec  */
  37.  
  38.   wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_window);
  39.   link_window(&Desk_window);
  40.  
  41.   set_idle_func(disp_time);               /* set background clock function  */
  42.  
  43.   wn_plst( CENTERED, 12, "This is the background window", &Desk_window);
  44.   wait_event();
  45.  
  46.   wn_create(20, 5, 60, 20, SLD_BDR, WN_POPUP, wnp);
  47.   wn_color(YELLOW, BLUE, wnp);            /* change the window colors       */
  48.   wn_bdr_color(WHITE, BLUE, wnp);         /* change the border's colors     */
  49.   link_window(wnp);
  50.   
  51.   wn_plst( CENTERED, 6, "This is the popup window", wnp);
  52.   wn_plst( CENTERED, 7, "Notice the clock in the lower right", wnp);
  53.   wn_plst( CENTERED, 8, "hand corner, updating in the background", wnp);
  54.   wait_event();                           /* wait for a keystroke           */
  55.  
  56.   unlink_window(wnp);                     /* remove the window from screen  */
  57.   wn_destroy(wnp);
  58.   wait_event();
  59.   set_idle_func(NULL);                    /* remove background function     */
  60.   unlink_window(&Desk_window);            /* remove the window from screen  */
  61.   wn_destroy(&Desk_window);
  62.   end_clock();
  63.   end_video();                            /* clean up before we exit        */
  64.   return(1);
  65. }
  66. /*** end of main ***/
  67.  
  68. /**************/
  69. /* ~disp_time */
  70. /*            ***************************************************************/
  71. /*  This routine is called in the background by wait_event and will display */
  72. /*  the time once per second.  Notice the use of the global variables       */
  73. /*  Uw_timers.  There is an array of four "countdown" timers that are user  */
  74. /*  accessible.  Each "timer tic" will decrement the counts by one, until   */
  75. /*  0 is reached.  By "reloading" the timer with "Tics_per_sec", we only    */
  76. /*  display the time of day once per second.  "Tics_per_sec" is set         */
  77. /*  by init_clock.                                                          */
  78. /****************************************************************************/
  79. int disp_time( void )
  80. {
  81.   time_t t;
  82.   if( !Uw_timers[0] )                           /* has one second passed?   */
  83.   {
  84.     Uw_timers[0] = Tics_per_sec;                /* if so, reload timer      */
  85.     t = time(NULL);                             /* get time                 */
  86.     mv_cs(55, V_rows-1, &Desk_window);          /* move window cursor       */
  87.     wn_st_qty(ctime(&t), 24, &Desk_window);     /* output 24 characters     */
  88.     return(1);
  89.   }
  90.   return(0);
  91. }
  92. /*** end of disp_time ***/
  93.  
  94. /*** END OF FILE ***/
  95.